import React from 'react'
import {useDispatch,useSelector} from "react-redux"
import { increment, decrement } from '../../store/slice/countSlice';
export default function Count() {
    const dispatch = useDispatch();
    const count = useSelector(state => {
        return state.count.count
    })
    const accumulation = () => {
        dispatch(increment(1))
    }
    const subtract = () => {
        dispatch(decrement(1))
    }
    const oddNumberOne = () => {
        if(count % 2 !==0 ){
        dispatch(increment(1))
        }
    }
    const waitTwoSeconds = () => {
        
    }
  return (
    <div>
        <h1>我是Count组件，我的值是{count}</h1>
        <button onClick={accumulation}>累加</button>
        <button onClick={subtract}>累减</button>
        <button onClick={oddNumberOne}>奇数加一</button>
        <button onClick={waitTwoSeconds}>等2s再加1</button>
    </div>
  )
}
